home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ShimSerialInternal.h
-
- Contains: Definitions for the PC Card Serial Driver
-
- Version: xxx put version here xxx
-
- Copyright: © 1995-1998 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: xxx put dri here xxx
-
- Other Contact: xxx put other contact here xxx
-
- Technology: xxx put technology here xxx
-
- */
-
- #ifndef _APPLE_ShimSERIALINTERNAL_
- #define _APPLE_ShimSERIALINTERNAL_
-
- #include <CommResources.h>
- #include <CRMSerialDevices.h>
- #include <Devices.h>
- #include <DriverServices.h>
- #include <Interrupts.h>
- #include <NameRegistry.h>
- //#include <PCCard.h>
- #include <Serial.h>
- #include <Types.h>
-
- #include "USB.h"
- #include "processes.h"
-
-
-
-
- // UART Specific Stuff
-
-
- // a hardwired value for the UART's clock speed
- // it's industry standard and I can't find a way
- // to get this info from a tuple... so...
-
- #define kUARTCrystalSpeed 1843200 // 1.8432 mhz
-
-
-
-
-
- // masks for uart line control register
-
- #define kLen8Bits 0x03
- #define kLen7Bits 0x02
- #define kLen6Bits 0x01
- #define kLen5Bits 0x00
-
- #define kStop1Bit 0x00
- #define kStop1_5Bits 0x04 // with len5Bits
- #define kStop2Bits 0x04 // with len6Bits - len8Bits
-
- #define kParNone 0x00
- #define kParOdd 0x08
- #define kParEven 0x18
- #define kParHigh 0x28
- #define kParLow 0x38
-
- #define kParStick 0x20
- #define kSetBreak 0x40
- #define kDLABSelect 0x80
-
-
- // FSM states ...
- typedef enum state_tag
- {
- kUnConfigured = 0,
- kConfiguring = 1,
- kConfigured = 2
- } state;
-
- // FSM events ...
- typedef enum event_tag
- {
- kNone = 0,
- kGetDescriptors = 1,
- kUSBGetFullConfigurationDescriptorComplete = 2,
- kUSBFindNextInterfaceDescriptorComplete = 3,
- kUSBFindNextEndpointDescriptorComplete = 4,
- kExit = 5,
- kConfigure = 6,
- kBug = 666
- } event;
-
- // FSM transitions ...
- typedef enum transition_tag
- {
- kInitial = 0,
- kStarting = 1
- } transition;
-
- // masks for the uart interrupt enable register
-
- #define kRXDataIntEnable 0x01
- #define kTXEmptyIntEnable 0x02
- #define kRXStatusIntEnable 0x04
- #define kModemIntEnable 0x08
-
-
-
-
-
- // masks for uart interrupt identification register
-
- #define kInterruptIDMask 0x0F
- #define kNoInterrupt 0x01
- #define kModemStatusInterrupt 0x00
- #define kTXEmptyInterrupt 0x02
- #define kRXDataInterrupt 0x04
- #define kRxStatusInterrupt 0x06
- #define kCharTimeoutInterrupt 0x0C
- #define kFIFOsEnabled 0xC0 // on 16550A, both bits 6 & 7 will be set, indicating fifos enabled
-
-
-
-
-
- // masks for uart fifo control register (write to the interrupt id reg)
-
- #define kFIFOEnable 0x01
- #define kFIFOClearRcvr 0x02
- #define kFIFOClearXmit 0x04
- #define kDMAMutliXfer 0x08
-
-
-
-
-
- // trigger values for uart fifo control register
-
- #define kFIFOTrigger1 0x00
- #define kFIFOTrigger4 0x40
- #define kFIFOTrigger8 0x80
- #define kFIFOTrigger14 0xC0
-
-
-
-
-
- // masks for uart modem control register
-
- #define kDTREnable 0x01
- #define kRTSEnable 0x02
- #define kIntEnable 0x08
-
-
-
-
-
- // masks for uart line status register
-
- #define kRxDataAvail 0x01
- #define kOverrunErr 0x02
- #define kParityErr 0x04
- #define kFramingErr 0x08
- #define kBreakDetect 0x10
- #define kRxErrMask 0x1E
- #define kTHREmpty 0x20
- #define kShiftEmtpy 0x40
-
-
-
-
-
- // masks for uart modem status register
-
- #define kCTSChanged 0x01
- #define kCTSCompliment 0x10
-
- #define kDSRChanged 0x02
- #define kDSRCompliment 0x20
-
- #define kRIChanged 0x04
- #define kRICompliment 0x40
-
- #define kDCDChanged 0x08
- #define kDCDCompliment 0x80
-
-
-
-
-
- // masks for pin replacement register
-
- #define kPRRdyBsy 0x02
- #define kPRCRdyBsy 0x20
-
-
-
-
-
- // masks for config options register
-
- #define kConfigOptComSel 0x03
- #define kConfigOptCdEnable 0x20
- #define kConfigOptLevIREQ 0x40
- #define kConfigOptSReset 0x80
-
-
-
-
-
- // masks for config status register
-
- #define kConfigStatPwrDwn 0x04
- #define kConfigStatAudio 0x08
- #define kConfigStatRI 0x10
- #define kConfigStatIOIs8 0x20
- #define kConfigStatSigChg 0x40
- #define kConfigStatChanged 0x80
-
-
-
-
-
- // the uart registers
-
- typedef struct {
- UInt8 RBR; // uart read buffer register (read only)
- UInt8 IER; // uart interrupt enable register (write only)
- UInt8 IIR; // uart interrupt identification register (read only)
- UInt8 LCR; // uart line control register
- UInt8 MCR; // uart modem control register
- UInt8 LSR; // uart line status register
- UInt8 MSR; // uart modem status register
- UInt8 SCR; // uart scratchpad register
- } UART;
-
- #define THR RBR // uart fifo transmit holding buffer (@ RBR) (write only)
- #define FCR IIR // uart fifo control register (@ IIR) (write only)
- #define DLL RBR // uart fifo divisor latch lsb (@ RBR)
- #define DLM IER // uart fifo divisor latch msb (@ IER)
-
-
-
-
-
- enum
- {
- kBuiltInBufferSize = 512,
- kMaxBaudRate = 115200
- };
-
-
-
-
-
- // Name Registry defines
-
- #define kNamePropertyName "name"
-
-
-
-
-
- // UPP info used for driver routines
-
- //typedef UniversalProcPtr DriverUPP;
-
- enum {
- uppDriverProcInfo = kRegisterBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterA0, SIZE_CODE(sizeof(ParmBlkPtr)))
- | REGISTER_ROUTINE_PARAMETER(2, kRegisterA1, SIZE_CODE(sizeof(DCtlPtr)))
- };
-
-
-
-
-
- // UPP info used to install the ".In" and ".Out" routines in the driver table
-
- typedef UniversalProcPtr InstallDriverUPP;
-
- enum {
- uppInstallDriverProcInfo = kRegisterBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterA0, SIZE_CODE(sizeof(Ptr)))
- | REGISTER_ROUTINE_PARAMETER(2, kRegisterD0, SIZE_CODE(sizeof(DriverRefNum)))
- };
-
- #define NewInstallDriverProc(userRoutine) \
- (InstallDriverUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppInstallDriverProcInfo, GetCurrentArchitecture())
-
- #define CallInstallDriverProc(userRoutine, newDrvrPtr, refNum) \
- CallUniversalProc((UniversalProcPtr)(userRoutine), uppInstallDriverProcInfo, (newDrvrPtr), (refNum))
-
-
-
-
-
- // UPP info used to remove the ".In" and ".Out" routines in the driver table
-
- typedef UniversalProcPtr RemoveDriverUPP;
-
- enum {
- uppRemoveDriverProcInfo = kRegisterBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(DriverRefNum)))
- };
-
- #define NewRemoveDriverProc(userRoutine) \
- (RemoveDriverUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppRemoveDriverProcInfo, GetCurrentArchitecture())
-
- #define CallRemoveDriverProc(userRoutine, refNum) \
- CallUniversalProc((UniversalProcPtr)(userRoutine), uppRemoveDriverProcInfo, (refNum))
-
-
-
-
-
- //
- // UPP info used to make the IODone call because IOCommandIsComplete won't work with this combination
- // of an native model driver and 68k model drivers.
- //
-
- typedef UniversalProcPtr IODoneUPP;
-
- enum {
- uppIODoneProcInfo = kRegisterBased
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(DCtlPtr)))
- | REGISTER_ROUTINE_PARAMETER(2, kRegisterD0, SIZE_CODE(sizeof(OSErr)))
- };
-
- #define CallIODoneProc(userRoutine, dce, result) \
- CallUniversalProc((UniversalProcPtr)(userRoutine), uppIODoneProcInfo, (dce), (result))
-
-
-
-
-
- //
- //
- // device driver data structure
- //
- // this is the header of a device driver
- // i don't suppose it is declared in the system header files
- // at any rate, it has been adapted to suit my needs...
- //
- //
- #if GENERATINGPOWERPC
- #pragma options align=mac68k
- #endif
-
- struct EJFDRVRHeader {
- short drvrCtlFlags;
- short drvrDelay;
- short drvrEMask;
- short drvrMenu;
- short drvrOpen;
- short drvrPrime;
- short drvrControl;
- short drvrStatus;
- short drvrClose;
- unsigned char drvrName[14];
-
- RoutineDescriptor ShimSerialStubOpen;
- RoutineDescriptor ShimSerialStubPrime;
- RoutineDescriptor ShimSerialStubControl;
- RoutineDescriptor ShimSerialStubStatus;
- RoutineDescriptor ShimSerialStubClose;
- };
- typedef struct EJFDRVRHeader EJFDRVRHeader;
-
- typedef EJFDRVRHeader *EJFDRVRHeaderPtr, **EJFDRVRHeaderHandle;
-
- #if GENERATINGPOWERPC
- #pragma options align=reset
- #endif
-
-
-
- typedef struct ShimSerialGlobals
- {
- // volatile UART *uartRegs; // base address of 8250/16450/16550
-
- // InterruptSetMember interruptSetMember; // interrupt tree node
- // InterruptEnabler interruptEnablerProc; // enable UART interrupts
- // InterruptDisabler interruptDisablerProc; // disable UART interrupts
-
- // USB Stuff
- USBPB pb;
-
- UInt8 errorString[256];
- USBDeviceDescriptor *device;
- USBConfigurationDescriptor *conf;
- USBInterfaceDescriptor *interface;
- UInt32 offset;
- USBEndPointDescriptor *ep[3];
- USBDeviceRef theModem;
- USBPipeRef bulkIn;
- USBPipeRef bulkOut;
- USBPipeRef interrupt;
- int onError;
- int retries;
-
- // input buffers
- UInt8 builtInBuffer[kBuiltInBufferSize]; // default input buffer
- UInt8 *inBufPtr; // pointer to current input buffer
- UInt16 inBufLen; // length of said buffer
- UInt16 inBufStartIndex; // circular queue indexes
- UInt16 inBufEndIndex;
-
- // serial driver state
-
- UInt8 xOnOffChar; // an xon or xoff char to be sent
- UInt8 lenParStop; // length, parity, stop bits for lcr register
- UInt8 peChar; // parity error replacement character
- UInt8 peAltChar; // parity error alternate replacement character
- UInt16 baudRate; // actual baud rate value i.e. 19200
- SerShk serShk; // handshake record (see inside mac, vol ii, serial drivers
- SerStaRec serStat; // serial status record (see inside mac, vol ii, serial drivers)
- UInt32 UARTCrystalSpeed; // retrieved by doing a Get_CAPS device request
-
- // stub drivers designed to work with serial driver model
-
- EJFDRVRHeaderPtr drvrIn; // driver header for the input dce
- DriverRefNum refNumIn; // reference number for the input driver
- DCtlHandle dceIn; // input dce for serial/modem card
- ParmBlkPtr pbIn; // current prime read request
- EJFDRVRHeaderPtr drvrOut; // driver header for the output dce
- DriverRefNum refNumOut; // reference number for the output driver
- DCtlHandle dceOut; // output dce for serial/modem card
- ParmBlkPtr pbOut; // current prime write request
-
- CRMRecPtr crm; // structures for the registering with crm
- CRMSerialPtr crmser;
-
- // socket information
-
- // RegEntryID cardRef;
- // RegEntryID deviceRef;
- // UInt32 socketNumber;
- // UInt32 deviceNumber;
-
- // miscellaneous hackery
-
- // Boolean useFIFO; // we’re running w/ a 16550A!
- Boolean openSession; // only allow one open session
-
- } ShimSerialGlobals;
-
- extern ShimSerialGlobals *gGlobals;
-
-
-
-
-
- /********************************************************************************************/
- //
- // Prototypes
- //
- /********************************************************************************************/
-
-
- // ShimSerialUtils.c
- void *GetDeviceProperty(const RegEntryID *entryID,const RegPropertyName *propertyName,RegPropertyValueSize *propertySize);
- void DisposeDeviceProperty(void *propertyToDispose);
-
-
-
- // ShimSerialRoutines.c
- OSStatus DoDriverIO( AddressSpaceID spaceID,
- IOCommandID ioCommandID,
- IOCommandContents ioCommandContents,
- IOCommandCode ioCommandCode,
- IOCommandKind ioCommandKind);
-
- OSStatus DoInitialization(SInt16 refNum,const RegEntryIDPtr deviceEntry,Boolean replacing);
- OSStatus DoFinalization(SInt16 refNum,const RegEntryIDPtr deviceEntry,Boolean beingReplaced);
- OSStatus DoOpen(ParmBlkPtr pb);
- OSStatus DoClose(ParmBlkPtr pb);
- OSStatus DoRead(IOCommandID ioCommandID,IOParam *pb);
- OSStatus DoWrite(IOCommandID ioCommandID,IOParam *pb);
- OSStatus DoKillIO(IOCommandID ioCommandID,IOParam *pb);
- OSStatus DoControl(CntrlParam *pb);
- OSStatus DoStatus(CntrlParam *pb);
- OSStatus DoDriverGestalt(CntrlParam *pb);
-
- OSStatus DoOpenSession(ParmBlkPtr pb);
- OSStatus DoCloseSession(ParmBlkPtr pb);
-
- OSStatus GetUARTBaseAddress(const RegEntryID *deviceEntry,UART **baseAddress);
-
-
-
-
-
- // UART Routines
- //
- // NOTE: We kept the “B_” names from Byrd, the Daffy Duck/M2
- // PC Card Serial Enabler, so we could easily find the original
- // code. I’ll probably fix this soon.
-
- // driver I/O routines
- OSErr B_Read(ShimSerialGlobals * globals, IOCommandID ioCommandID, IOParam * pb);
- OSErr B_Write(ShimSerialGlobals * globals, IOCommandID ioCommandID, IOParam * pb);
- OSErr B_FillReadRequest(ShimSerialGlobals * globals, IOParam * pb);
-
-
-
-
-
- // driver control call routines
- OSErr B_SerReset(ShimSerialGlobals * globals, UInt16 config);
- OSErr B_SetBuffer(ShimSerialGlobals * globals, Ptr newBuf, UInt16 bufLen);
- void B_SetSerShk(ShimSerialGlobals * globals, SerShk *shkNew, UInt16 csCode);
- void B_SendXOn(ShimSerialGlobals * globals, Boolean always);
- void B_SendXOff(ShimSerialGlobals * globals, Boolean always);
- void B_EnableDTR(ShimSerialGlobals * globals, Boolean enable);
- void B_EnableRTS(ShimSerialGlobals * globals, Boolean enable);
- void B_SetBreak(ShimSerialGlobals * globals, Boolean setBreak);
- void B_SetLenParStop(ShimSerialGlobals * globals, UInt8 lenParStop);
- UInt16 B_SetBaudRate(ShimSerialGlobals * globals, UInt32 baudRate);
- void B_SetParErrChar(ShimSerialGlobals * globals, Boolean alt, char peChar, char peAltChar);
-
-
-
-
-
- // driver status call routines
- void B_SerStatus(ShimSerialGlobals * globals, SerStaRec *statRec);
- UInt32 B_SerGetBuf(ShimSerialGlobals * globals);
-
-
-
-
-
- // handling card services device interrupt
- InterruptMemberNumber B_UARTInterrupt(InterruptSetMember ISTmember, void *refCon, UInt32 theIntCount);
-
- void B_UARTModemStatus(ShimSerialGlobals * globals);
- void B_UARTOutput(ShimSerialGlobals * globals);
- void B_UARTInput(ShimSerialGlobals * globals);
-
-
-
-
-
- // controlling the modem card uart
- void B_EnableSerialDevice(ShimSerialGlobals * globals);
- void B_DisableSerialDevice(ShimSerialGlobals * globals);
- void B_InputFlowControl(ShimSerialGlobals * globals);
- void B_EnableInput(ShimSerialGlobals * globals, Boolean enable);
- void B_EnableOutput(ShimSerialGlobals * globals);
-
-
-
-
-
- // ShimSerialStub.c
- OSErr initUSBStuff(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
- OSErr InstallDriverControlEntries(void);
- Boolean UniqueDrvrName(StringPtr name);
- void GetUniqueDrvrName(StringPtr name,StringPtr base);
- short GetUniqueRefNum(void);
- OSErr InstallCRM(void);
- void GetUniqueCRMPortName(StringPtr name);
- void RemoveCRM(void);
- OSErr RemoveDriverControlEntries (void);
- OSErr ShimSerialStubOpen(ParmBlkPtr pb,DCtlPtr dce);
- OSErr ShimSerialStubClose(ParmBlkPtr pb,DCtlPtr dce);
- OSErr ShimSerialStubPrime(ParmBlkPtr pb,DCtlPtr dce);
- OSErr ShimSerialStubControl(ParmBlkPtr pb,DCtlPtr dce);
- OSErr ShimSerialStubStatus(ParmBlkPtr pb,DCtlPtr dce);
- void ShimSerialStubIODone(ParmBlkPtr pb,DCtlPtr dce,OSErr result);
-
-
- // SerialBox.c
- void serialBoxEntry(USBDeviceRef device, USBDeviceDescriptor *desc);
- static void StartStatusMonitor(USBPipeRef interruptPipe);
- static void InitializePB(USBPB *pb, USBDeviceRef ref, USBCompletion handler);
- void USBStartReadPolling(void);
- Boolean TimeoutPreviousRequest(void);
- void USBSetBaudRateDivisor(UInt16 divisor);
- void USBSetParChar(UInt8 parChar);
- void USBSetStopBits(UInt16 stopBits);
- void USBSetDataBits(UInt16 dataBits);
- void USBSetParityBits(UInt16 parityBits);
- void USBSetControl(UInt16 state);
- void USBSetDTRState(Boolean state);
- UInt32 USBGetModemStatus(void);
- void USBSetBreakState(Boolean state);
- void USBSetRTSState(Boolean state);
- void ShimInput(UInt8 *buf, UInt32 count);
- void readCompletion(USBPB *pb);
- void USBStartReadPolling();
- void USBStopReadPolling();
- void writeCompletion(USBPB *pb);
- OSStatus USBSerialWrite(IOParam *pb);
- void KillUSBIO(void);
-
-
- #endif /* _APPLE_ShimSERIALINTERNAL_ */
-